const User = require('../model/user.model')

class UserService {
    async createUser(user_name, pass_word) {
        const res = await User.create({
            user_name,
            pass_word
        })
        return res.dataValues;
    }
    async getUserInfo({ id, user_name, pass_word, is_admin }) {
        const whereOpt = {};
        id && Object.assign(whereOpt, { id });
        user_name && Object.assign(whereOpt, { user_name });
        pass_word && Object.assign(whereOpt, { pass_word });
        is_admin && Object.assign(whereOpt, { is_admin });

        const res = await User.findOne({
            attributes: ['id', 'user_name', 'pass_word', 'is_admin'],
            where: whereOpt
        })
        
        return res ? res.dataValues : null;
    }
}

module.exports = new UserService();